#!/bin/bash

IP=$1
PASSWD=$2
HOST_STATUS=$3

source $PWD/../config.ini

# 配置免密码操作
/usr/bin/sshpass -p"${PASSWD}" /usr/bin/ssh-copy-id root@${IP} > $WORK_DIR/logs/install_master_elb_$IP.log 2>&1
if [ $? -ne 0 ]; then
    echo $IP "ssh-copy-id failed!"
else
    echo $IP "ssh-copy_id success!"
fi

mkdir -p $WORK_DIR/install_master_elb/nodes/$IP
echo "[nodes]" > $WORK_DIR/install_master_elb/nodes/$IP/hosts
echo "${IP}" >> $WORK_DIR/install_master_elb/nodes/$IP/hosts

/usr/bin/ansible-playbook -i $WORK_DIR/install_master_elb/nodes/$IP/hosts $WORK_DIR/install_master_elb/ansible_yaml/install_master_elb.yaml --extra-vars "HOST_IP=${IP} HOST_STATUS=${HOST_STATUS} WORK_DIR=${WORK_DIR}" >> $WORK_DIR/logs/install_master_elb_$IP.log 2>&1